#include <iostream>
#include <gl\glew.h>
#include <gl\glut.h>
#include "global.h"
#include "MyCamera.h"
#include "FPS.h"
using namespace std;

MyCamera  myCamera;
FPS fps;

void keyboardFunc(unsigned char key, int x,int y)
{
	if(key=='Q'||key=='q'||key==27)
		exit(0);
}
void windowResizeFunc(GLsizei width, GLsizei heigth)
{
	glViewport(0,0,width,width);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60,1.0,0.01,10);
	glViewport(0,0,width,width);
}
void renderScene()
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(!GetAsyncKeyState(VK_SHIFT))
		myCamera.update();
	else 
		myCamera.camLook();

	glColor3f(1.0,0.5,0.5);
	glBegin(GL_TRIANGLES);
	glVertex2f(-0.5,-0.5);
	glVertex2f(0.5,-0.5);
	glVertex2f(0,0.5);
	glEnd();
	

	//fps.update();
	//glutSetWindowTitle("10");
	//glutSetWindowTitle(fps.dis_fps);

	glutSwapBuffers();
}
void updateScene()
{
	glutPostRedisplay();
}
int main(int argc,char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GL_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(WINDOW_SIZE,WINDOW_SIZE);
	glutCreateWindow("In Time Radiosity");
	myCamera.positionCamera(CAMERA_POS,CAMERA_VIEW,CAMERA_UP);
	
	GLfloat tmp[4]={0.0,2.0,2.0,1.0};
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0,GL_POSITION,tmp);
	glEnable(GL_LIGHTING);

	glutKeyboardFunc(keyboardFunc);
	glutReshapeFunc(windowResizeFunc);
	glutDisplayFunc(renderScene);
	glutIdleFunc(updateScene);

	glewInit();
	glutMainLoop();
	return 0;
}